package org.agent.service.premission;

import java.util.List;

import org.agent.dao.premission.PremissionMapper;
import org.agent.pojo.Premission;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service("premissionService")
public class PremissionServiceImpl implements PremissionService {
	@Autowired
	private PremissionMapper premissionMapper;
	@Override
	public List<Premission> getPremissionList(Premission premission) {
		// TODO Auto-generated method stub
		return premissionMapper.getPremissionList(premission);
	}

	@Override
	public int addPremission(Premission premission) {
		// TODO Auto-generated method stub
		return premissionMapper.addPremission(premission);
	}

	@Override
	public int modifyPremission(Premission premission) {
		// TODO Auto-generated method stub
		return premissionMapper.modifyPremission(premission);
	}

	@Override
	public int deletePremission(Premission premission) {
		// TODO Auto-generated method stub
		return premissionMapper.deletePremission(premission);
	}

	/**
	 * 添加一个权限----先删除再添加，保证权限的唯一性，避免冗余
	 * @param Premission premission,String checkList
	 * @return
	 * */
	@Override
	public void tx_delAddPremission(Premission premission, String checkList) {
		// TODO Auto-generated method stub
		//1.组合所有角色和功能的映射
		String[] funcList = checkList.split(",");
		
		//2.保存（删除再添加）
		premissionMapper.deletePremission(premission);//premission对象的其他属性要从action里面set
		if(null!=funcList&&!funcList.equals("")){
			for (int i = 0; i < funcList.length; i++) {
				premission.setFunctionId(Integer.valueOf(funcList[i]));
				premissionMapper.addPremission(premission);//只改变funcId
			}
			
		}
		
	}

}
